package com.ewing.busi.pay.dao;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.ewing.busi.pay.model.PayWxPrepayidDetail;
import com.ewing.common.constants.IsEff;
import com.ewing.core.jdbc.BaseDao;
import com.ewing.core.jdbc.util.PageBean;

@Repository
public class PayWxPrepayidDetailDao {
  /**
   * 默认生成的该类的LOG记录器，使用slf4j组件。避免产生编译警告，使用protected修饰符。
   */
  protected final static Logger LOG = LoggerFactory.getLogger(PayWxPrepayidDetailDao.class);

  @Resource
  private BaseDao baseDao;

  public List<PayWxPrepayidDetail> getByBizId(String bizId) {
    return baseDao.find("biz_id='" + bizId + "'", PayWxPrepayidDetail.class);
  }

  public PayWxPrepayidDetail getByBizIdAndIsEff(String bizId, IsEff isEff) {
    StringBuilder condition = new StringBuilder("bizId='" + bizId + "'");
    condition.append("and iseff = '" + isEff.getValue() + "'");
    return baseDao.findOne(condition.toString(), PayWxPrepayidDetail.class);
  }
  
  public PayWxPrepayidDetail getByLastestBizId(String bizId){
    StringBuilder condition = new StringBuilder("bizId='" + bizId + "'");
    
    PageBean<PayWxPrepayidDetail> pageBean = baseDao.pageQuery(condition.toString(), " order by id desc", 1, 1, PayWxPrepayidDetail.class);
    List<PayWxPrepayidDetail> list = null != pageBean ? pageBean.getResult() : null;
    return CollectionUtils.isNotEmpty(list) ? list.get(0) : null;
  }
  
  
}
